package com.ruoyi.cc.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.cc.domain.Message;
import com.ruoyi.cc.service.IMessageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 活动中心Controller
 * 
 * @author ruoyi
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/activity")
public class MessageController extends BaseController
{
    @Autowired
    private IMessageService messageService;
    /**
     * 查询isLaunch不为0的活动中心列表
     */
    @GetMapping("/lists/launch")
    public TableDataInfo listByIsLaunch()
    {
        startPage();
        List<Message> list = messageService.selectMessageListByIsLaunch();
        return getDataTable(list);
    }

    /**
     * 通过审核状态和用户ID查询活动中心列表
     */
    @GetMapping("/lists")
    public TableDataInfo listByStatusAndUid(Message message)
    {
        startPage();
        List<Message> list = messageService.selectMessageListByStatusAndUid(message);
        return getDataTable(list);
    }

    /**
     * 查询活动中心列表
     */
//    @RequiresPermissions("cc:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(Message message)
    {
        startPage();
        List<Message> list = messageService.selectMessageList(message);
        return getDataTable(list);
    }

    /**
     * 导出活动中心列表
     */
    @RequiresPermissions("cc:activity:export")
    @Log(title = "活动中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Message message)
    {
        List<Message> list = messageService.selectMessageList(message);
        ExcelUtil<Message> util = new ExcelUtil<Message>(Message.class);
        util.exportExcel(response, list, "活动中心数据");
    }

    /**
     * 获取活动中心详细信息
     */
//    @RequiresPermissions("cc:activity:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(messageService.selectMessageById(id));
    }

    /**
     * 新增活动中心
     */
//    @RequiresPermissions("cc:activity:add")
    @Log(title = "活动中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Message message)
    {
        return toAjax(messageService.insertMessage(message));
    }

    /**
     * 修改活动中心
     */
//    @RequiresPermissions("cc:activity:edit")
    @Log(title = "活动中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Message message)
    {
        return toAjax(messageService.updateMessage(message));
    }

    /**
     * 删除活动中心
     */
//    @RequiresPermissions("cc:activity:remove")
    @Log(title = "活动中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(messageService.deleteMessageByIds(ids));
    }
}
